package com.gss.armory.service;

import java.util.HashMap;
import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;

import com.gss.armory.domain.BusinessUnitDetailsDTO;
import com.gss.armory.domain.CompanyDetailsDTO;
import com.gss.armory.domain.DepartmentDetailsDTO;
import com.gss.armory.domain.LocationDetailsDTO;
import com.gss.common.util.ApplicationMaps;

@Service
public class CommonApplicationService {
	
	private Logger logger = Logger.getLogger(CommonApplicationService.class);
	
	public HashMap<Integer,String> getBUNameIdMapForCompanyId(int companyId){
		HashMap<Integer,String> BU_ID_NAME_MAP = new HashMap<Integer, String>();
		CompanyDetailsDTO companyDetailsDTO = ApplicationMaps.COMPANYID_COMPANY_MAP.get(companyId);
		if(null != companyDetailsDTO){
			if(null != companyDetailsDTO.getBusinessUnitList()){
				for(BusinessUnitDetailsDTO buDetails : companyDetailsDTO.getBusinessUnitList()){
					BU_ID_NAME_MAP.put(buDetails.getBuId(), buDetails.getBuName());
				}
			}
		}
		logger.debug("BU_ID_NAME_MAP"+BU_ID_NAME_MAP);
		return BU_ID_NAME_MAP;
	}

	public HashMap<Long, String> getDepttIdNameMapForBUId(int buId){
		HashMap<Long,String> DEPTT_ID_NAME_MAP = new HashMap<Long, String>();
		List<DepartmentDetailsDTO> buDetails = ApplicationMaps.BU_DEPTS_MAP.get((long)buId);
		if(null != buDetails){
			
				for(DepartmentDetailsDTO deptt : buDetails){
					DEPTT_ID_NAME_MAP.put(deptt.getDdId(), deptt.getDdName());
				}
		}
		logger.debug("BUID_BU_MAP" + DEPTT_ID_NAME_MAP);
		return DEPTT_ID_NAME_MAP;
	}

	public HashMap<Long, String> getLocforCompany(int cdId) {
		HashMap<Long, String> locMap = new HashMap<Long, String>();
		
		logger.debug(ApplicationMaps.COMPANY_LOC_MAP.get(cdId));
		List<LocationDetailsDTO> mappedLocations = ApplicationMaps.COMPANY_LOC_MAP.get(cdId);
		
		if(null != mappedLocations){
			for(LocationDetailsDTO locs : mappedLocations){
				locMap.put(locs.getLdId(), locs.getLdName());
			}
		}
		logger.debug("locMap"+locMap);
		return locMap;
	}
}
